#ifndef __IF_SOC_EXTI_H__
#define __IF_SOC_EXTI_H__

#include <functional>
#include <stdint.h>
#include "soc/iperipheral.h"
#include "soc/soc_comm_def.h"


/// @brief 
class IF_SOC_Exti : public IPeripheralEx<IF_SOC_Exti, GPIO_EXTI_MAX, 0>
{
public:
    using EXTI_FUNC_ANY = std::function<void(IF_SOC_Exti &sender, GpioExtiDevId extiId)>;
    using EXTI_FUNC = std::function<void(IF_SOC_Exti &sender)>;

public:
    virtual void InitDevId(GpioExtiDevId extiId) = 0;
    
    virtual void SetExtiCallBack(const EXTI_FUNC &func) = 0;
    virtual void RaiseExtiCallBack() = 0;

public:
    inline static void SetExtiCallBackAny(const EXTI_FUNC_ANY &func){m_anyFunc = func;}
    inline static void RaiseExit_IRQ_Global(GpioExtiDevId extiId)
    {
        auto p = GetInstanceById((int)extiId);

        if(p != nullptr)
            p->RaiseExtiCallBack();

        if(m_anyFunc)
            m_anyFunc(*p, extiId);
    }
    
private:
    static IF_SOC_Exti::EXTI_FUNC_ANY m_anyFunc;
};

inline IF_SOC_Exti::EXTI_FUNC_ANY IF_SOC_Exti::m_anyFunc = nullptr;

#endif // __IF_SOC_EXTI_H__
